package woniuxy.control;/*
 * @Author: Tiangle
 * @Date:   {DATE}
 * @TIME:   {TIME}
 * @Project_Name: {PROJECT_NAME}
 * @Package_Name: {PACKAGE_NAME}
 */

import woniuxy.commons.JDKProxy;
import woniuxy.commons.PrintCitys;
import woniuxy.model.City;
import woniuxy.model.Country;
import woniuxy.service.CountryService;
import woniuxy.service.impl.CountryServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/country")
public class CountryServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        CountryService proxy = new JDKProxy<CountryService>().getProxy(new CountryServiceImp());
        String code = req.getParameter("code");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        if (code==""||code==null){
            List<City> citys = proxy.getCitys();
            PrintCitys.pc2(resp,citys);
        }else {
            Country country = proxy.getCountry(code);

            PrintCitys.pc(resp,country);
        }



    }
}
